<?php

/**
 * Api Model 类
 * @author: 喵了个咪  <wenzhenxi@vip.qq.com> 2015-07-23
 */
class Model_Manage extends PhalApi_Model_NotORM {

    protected function getTableName($id) {

        return 'manage';
    }

    /**
     * 获取用户ID 用户登录
     */
    public function getDevelopersByName($username, $password) {

        return $this->getORM()->select('adminId,type,name,phone')->where('userName', $username)->where('passWord', $password)->fetch();
    }

    /**
     * 通过ID 获取管理员信息
     */
    public function getDevelopersById($adminId) {

        return $this->getORM()->select('*')->where('type', 1)->where('adminId', $adminId)->fetch();
    }

    /**
     * 获取管理员列表信息
     */
    public function getManagList() {

        return $this->getORM()->select('adminId,userName,name,type,phone')->fetchAll();
    }

    /**
     * 通过用户名获取管理员Id
     */
    public function getuserNameById($userName) {

        return $this->getORM()->select('adminId')->where('userName', $userName)->fetch();
    }

    /**
     * 创建用户
     */
    public function increaseManage($userName, $passWord, $name, $phone) {

        $data             = array();
        $data['userName'] = $userName;
        $data['passWord'] = $passWord;
        $data['name']     = $name;
        $data['phone']    = $phone;
        return $this->getORM()->insert($data);
    }

    /**
     * 修改用户
     */
    public function updateManage($adminId, $passWord, $name, $phone) {
        //如果传递的ID 是 MD5字符串全部为0 则不更新
        $data = array();
        if ($passWord != '0000000000000000000000000000000000000000000000000000000000000000') {
            $data['passWord'] = $passWord;
        }
        $data['name']  = $name;
        $data['phone'] = $phone;
        return $this->getORM()->where('adminId', $adminId)->update($data);
    }

    /**
     * 修改用户
     */
    public function updateManage2($uId, $name, $phone) {

        $data          = array();
        $data['name']  = $name;
        $data['phone'] = $phone;
        return $this->getORM()->where('adminId', $uId)->update($data);
    }

    /**
     * 修改用户
     */
    public function updateManageType($adminId, $type) {

        $data         = array();
        $data['type'] = $type;
        return $this->getORM()->where('adminId', $adminId)->update($data);
    }

    /**
     * 修改用户
     */
    public function setPassWord($newPw, $uId) {

        $data             = array();
        $data['passWord'] = $newPw;
        return $this->getORM()->where('adminId', $uId)->update($data);
    }
}
